package com.jsoup;
import java.io.IOException;   
import java.io.UnsupportedEncodingException;   
import java.net.MalformedURLException;   
  
import org.jsoup.Jsoup;   
import org.jsoup.nodes.Document;   
import org.jsoup.nodes.Element;   
import org.jsoup.select.Elements;   
  
  
/**  
* 获取Ku6视频  
* @author honny.huang  
* 2011-3-31  
* http://hi.juziku.com/sunlightcs/  
*/  
public class JsoupParseK6 {   
    private static String URL = "http://v.ku6.com/special/show_4027224/XFlByjLKGajkK_o-.html";   
       
    public static void main(String[] args) throws Exception{   
           
        Document doc = getURLContent();   
           
           
        /**  
         * 获取视频地址  
         */  
        Element flashEt = doc.getElementById("outSideSwfCode");   
        String flash = flashEt.attr("value");   
        System.out.println("视频地址："+flash);   
           
        /**  
         * 获取视频缩略图  
         */  
        Element picEt = doc.getElementById("plVideosList");   
        if(picEt!=null){   
            Elements pics = picEt.getElementsByTag("img");   
            String pic = pics.get(0).attr("src");   
            System.out.println("视频缩略图："+pic);   
               
            /**  
             * 获取视频时长  
             */  
            Element timeEt = picEt.select("span.review>cite").first();    
            String time = timeEt.text();   
            System.out.println("视频时长："+time);   
        }else{   
            String pic = doc.getElementsByClass("s_pic").first().text();   
            System.out.println("视频缩略图："+pic);   
        }   
           
    }   
       
    /**  
     * 获取Ku6网页的内容  
     */  
    private static Document getURLContent() throws MalformedURLException, IOException, UnsupportedEncodingException {   
        Document doc = Jsoup.connect(URL)   
          .data("query", "Java")   
          .userAgent("Mozilla")   
          .cookie("auth", "token")   
          .timeout(3000)   
          .post();   
        return doc;   
    }   
  
}  
